﻿using furion.blog.Application.Contracts;
using furion.blog.Domain.IRepositories;
using furion.blog.Domain.MySQL;
using furion.blog.Domain.Query.Role;
using furion.blog.Domain.Shared.Vo.Role;
using Furion.DependencyInjection;
using Mapster;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Application
{
    public class RoleService : IRoleService, ISingleton
    {
        private readonly IRoleRepository _roleRepository;

        public RoleService(IRoleRepository roleRepository)
        {
            this._roleRepository = roleRepository;
        }

        /// <summary>
        /// 角色详细信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<RoleDetailVO> Detail(long id)
        {
            Role role = await this._roleRepository.FindById(id);
            if (role == null)
            {
                return null;
            }
            return role.Adapt<RoleDetailVO>();
        }


        /// <summary>
        /// 查询所有角色
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<List<Role>> All(RoleDetailQuery query)
        {
            var ret = await this._roleRepository.All(query);
            return ret;
        }

    }
}
